﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace UIPrototyper
{
    class ScreenConverter:StringConverter
    {
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            return new StandardValuesCollection(ProjectSingleton.Project.Screens.Values.ToArray());
            
        }

        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (value.GetType() == typeof(string))
            {
                foreach (Screen s in ProjectSingleton.Project.Screens.Values)
                {
                    if (s.ID == value.ToString().Split('{')[value.ToString().Split('{').Length - 1].Replace("}", ""))
                        return s.Name + " {" + s.ID + "}";
                }
            }

            return base.ConvertFrom(context, culture, value);
        }
    }
}
